package com.examination.controller.safetyModel;


import com.examination.entity.Riskshow;
import com.examination.service.safetyModel.RiskshowService;
import com.examination.service.staffModel.StaffService;
import com.examination.util.JsonResult;
import com.examination.util.Msg;
import com.examination.util.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Api(description = "隐患风险信息记录")
@RestController
@RequestMapping("riskshow")
@CrossOrigin
public class RiskshowController {
    @Autowired
    private RiskshowService riskshowService;

    @Autowired
    private StaffService staffService;

    @ApiOperation(value = "分页查询隐患风险信息" , notes = "测试数据:{\"pageNo\": 1,\n" +
            "  \"pageSize\": 10}")
    @PostMapping("/findRiskshow")
    public Page<Riskshow> findRiskshow(@RequestBody Map map) {
        Page<Riskshow> page = new Page<Riskshow>();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setItems(riskshowService.findRiskshow(map));
        page.setTotal(riskshowService.total(map));
        return page;
    }

    @ApiOperation(value = "增加隐患信息" , notes = "")
    @PostMapping("insertRiskshow")
    public JsonResult insertRiskshow(@RequestBody Map map) {
        System.out.println("map:"+map);
        JsonResult jsonResult = new JsonResult();
        int i = riskshowService.insertRiskshow(map);
        if(i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("增加成功!");
            return jsonResult;
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("增加失败!");
            return jsonResult;
        }
    }


    @ApiOperation(value = "整改上报" , notes = "")
    @PostMapping("updateRiskshow")
    public JsonResult updateRiskshow(@RequestBody Map map) {
        JsonResult jsonResult = new JsonResult();
        int i = riskshowService.updateRiskshow(map);
        if(i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("上报成功!");
            return jsonResult;
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("上报失败!");
            return jsonResult;
        }
    }

    @ApiOperation(value = "删除隐患信息" , notes = "")
    @PostMapping("deleteRiskshow")
    public JsonResult deleteRiskshow(@RequestBody Map map) {
        JsonResult jsonResult = new JsonResult();
        int i = riskshowService.deleteRiskshow(map);
        if(i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("删除成功!");
            return jsonResult;
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除失败!");
            return jsonResult;
        }
    }

    @ApiOperation(value = "查找个人隐患记录" , notes = "")
    @PostMapping("findRiskshowByStaffId")
    public List<Riskshow> find_riskshow_sid(@RequestBody Map map) {
        return riskshowService.findRiskshowByStaffId(map);
    }

    @ApiOperation(value = "修改隐患信息审核状态有效/无效(同时给予积分)" , notes = "")
    @PostMapping("/upd_state")
    public JsonResult upd_state(@RequestBody Map map) {
        System.out.println("map:"+map);
        JsonResult jsonResult = new JsonResult();
        int i = riskshowService.upd_state(map);
        int p = staffService.updateEndIntegralL(map);
        if (i == 1 && p == 1) {
            jsonResult.setCode(200);
            jsonResult.setMessage("审核成功!");
            return jsonResult;
        } else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("审核失败!");
            return jsonResult;
        }

    }
}
